import { Controller, HttpCode, Post, Req, UploadedFile, UseInterceptors } from '@nestjs/common';
import { UploadService } from './upload.service';
import { FileInterceptor } from '@nestjs/platform-express';
import { ReqAttrs } from '../../constant';
import { ResponseUtilService } from '@app/response-util';

@Controller('upload')
export class UploadController {
    constructor(
        private readonly service:UploadService
    ){}

    @Post('upload')
    @HttpCode(200)
    @UseInterceptors(FileInterceptor('file'))
    async upload(@UploadedFile() file: Express.Multer.File, @Req() req) {
        const r = await this.service.upload(file, req[ReqAttrs.USER_ID])
        return ResponseUtilService.successRes(r)
    }

    @Post('uploadp')
    @HttpCode(200)
    async uploadp(@Req() req) {
        return ResponseUtilService.successRes(Date.now() + '.png')
    }
}
